const express = require('express')
const axios = require('axios')
const app = express()

app.get('/repositories/:q', (req, res) => {
  const q = req.params.q

  setTimeout(() => {
    res.send({
      status: 0,
      data: {name: 'vue', html_url: 'http://www.github.com/vue'}
    })
  }, 1000)

  // axios({
  //   method: 'GET',
  //   url: 'https://api.github.com/search/repositories',
  //   params: {
  //     q,
  //     sort: 'starts'
  //   }
  // }).then(response => {
  //   const {name, html_url} = response.data.item[0]
  //   res.send({
  //     status: 0,
  //     data: {name, html_url}
  //   })
  // })
})

app.listen('4000', () => {
  console.log('服务器启动成功, http://localhost:4000')
})